package org.fund.controller;

import com.github.pagehelper.PageInfo;
import org.fund.base_service.domain.IncomeRecord;
import org.fund.base_service.domain.input.base.PageDomain;
import org.fund.base_service.service.IncomeRecordService;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.fund.common.core.domain.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 收益记录(IncomeRecord)表控制层
 *
 * @author makejava
 * @since 2022-03-13 01:24:53
 */
@RestController
@RequestMapping("/incomeRecord")
@Api(tags = "收益记录 待完善")
public class IncomeRecordController {
    /**
     * 服务对象
     */
    @Autowired
    private IncomeRecordService incomeRecordService;

    /**
     * 分页查询
     *
     * @return 查询结果
     */
    @PostMapping("/list")
    @ApiOperation(value = "分页查询 这个可用")
    public BaseResult<PageInfo<IncomeRecord>> queryByPage(@RequestBody PageDomain pageDomain) {
        return BaseResult.success(this.incomeRecordService.queryByPage(pageDomain));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping
    @ApiOperation(value = "通过主键查询单条数据")
    public BaseResult<IncomeRecord> queryById(@RequestParam("id") Integer id) {
        return BaseResult.success(this.incomeRecordService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param incomeRecord 实体
     * @return 新增结果
     */
    @PostMapping("/add")
    @ApiOperation(value = "新增数据")
    public BaseResult<IncomeRecord> add(@RequestBody IncomeRecord incomeRecord) {
        return BaseResult.success(incomeRecordService.insert(incomeRecord));
    }

    /**
     * 编辑数据
     *
     * @param incomeRecord 实体
     * @return 编辑结果
     */
    @PutMapping("/edit")
    @ApiOperation(value = "编辑数据")
    public BaseResult<IncomeRecord> edit(@RequestBody IncomeRecord incomeRecord) {
        return BaseResult.success(incomeRecordService.update(incomeRecord));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @ApiOperation(value = "删除")
    @DeleteMapping
    public BaseResult<Boolean> deleteById(Integer id) {
        return BaseResult.success(incomeRecordService.deleteById(id));
    }

}

